package com.sanqing.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sanqing.bean.Course;
import com.sanqing.bean.CourseName;
import com.sanqing.bean.Employee;
import com.sanqing.dao.CourseDAO;
import com.sanqing.factory.CourseDAOFactory;

/**
 * Servlet implementation class Course
 */
@WebServlet("/CourseShow")
public class CourseShow extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CourseShow() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");//设置编码
		
		Employee employee=(Employee)request.getSession().getAttribute("employee");
		
		CourseDAO courseDAO=CourseDAOFactory.getCourseDAOInstance();
		
		Course course=courseDAO.findCourse(employee.getEmployeeID());
		
		String CourseMessage=course.getCoureseContent();
		
		CourseName Monday=new CourseName();
		ChangeFunction(Monday,CourseMessage);
		CourseMessage=CourseMessage.substring(4);
		
		CourseName Tuesday=new CourseName();
		ChangeFunction(Tuesday,CourseMessage);
		CourseMessage=CourseMessage.substring(4);
		
		CourseName Wednesday=new CourseName();
		ChangeFunction(Wednesday,CourseMessage);
		CourseMessage=CourseMessage.substring(4);
		
		CourseName Thursday=new CourseName();
		ChangeFunction(Thursday,CourseMessage);
		CourseMessage=CourseMessage.substring(4);
		
		CourseName Friday=new CourseName();
		ChangeFunction(Friday,CourseMessage);
		
		
		
		request.setAttribute("Monday", Monday);
		request.setAttribute("Tuesday", Tuesday);
		request.setAttribute("Wednesday", Wednesday);
		request.setAttribute("Thursday", Thursday);
		request.setAttribute("Friday", Friday);
		
		ServletContext servletContext=getServletContext();
		RequestDispatcher dispatcher=servletContext.getRequestDispatcher("/View/course.jsp");
		dispatcher.forward(request, response);
		
		
	}
	public static void ChangeFunction(CourseName day,String Message)
	{
		
	switch(Message.charAt(0))
	{
	 case '1':
		 day.setFirst("语文");
		 break;
	 case '2':
		 day.setFirst("数学");
		 break;
	 case '3':
		 day.setFirst("生物");
		 break;
	 case '4':
		 day.setFirst("地理");
		 break;
	 case '5':
		 day.setFirst("历史");
		 break;
	 case '6':
		 day.setFirst("物理");
		 break;
	 case '7':
		 day.setFirst("化学");
		 break;
	 case '8':
		 day.setFirst("体育");
		 break;
	 case '9':
		 day.setFirst("英语");
		 break;
		 
     default: break;
	}
	switch(Message.charAt(1))
	{
	 case '1':
		 day.setSecond("语文");
		 break;
	 case '2':
		 day.setSecond("数学");
		 break;
	 case '3':
		 day.setSecond("生物");
		 break;
	 case '4':
		 day.setSecond("地理");
		 break;
	 case '5':
		 day.setSecond("历史");
		 break;
	 case '6':
		 day.setSecond("物理");
		 break;
	 case '7':
		 day.setSecond("化学");
		 break;
	 case '8':
		 day.setSecond("体育");
		 break;
	 case '9':
		 day.setSecond("英语");
		 break;
		 
     default: break;
	}
	switch(Message.charAt(2))
	{
	 case '1':
		 day.setThrid("语文");
		 break;
	 case '2':
		 day.setThrid("数学");
		 break;
	 case '3':
		 day.setThrid("生物");
		 break;
	 case '4':
		 day.setThrid("地理");
		 break;
	 case '5':
		 day.setThrid("历史");
		 break;
	 case '6':
		 day.setThrid("物理");
		 break;
	 case '7':
		 day.setThrid("化学");
		 break;
	 case '8':
		 day.setThrid("体育");
		 break;
	 case '9':
		 day.setThrid("英语");
		 break;
		 
     default: break;
	}
	switch(Message.charAt(3))
	{
	 case '1':
		 day.setFourth("语文");
		 break;
	 case '2':
		 day.setFourth("数学");
		 break;
	 case '3':
		 day.setFourth("生物");
		 break;
	 case '4':
		 day.setFourth("地理");
		 break;
	 case '5':
		 day.setFourth("历史");
		 break;
	 case '6':
		 day.setFourth("物理");
		 break;
	 case '7':
		 day.setFourth("化学");
		 break;
	 case '8':
		 day.setFourth("体育");
		 break;
	 case '9':
		 day.setFourth("英语");
		 break;
		 
     default: break;
	}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
